//
//  VehicleAdditionController.m
//  StarOrangeStaff
//
//  Created by lshenrong on 2020/6/30.
//  Copyright © 2020 lshenrong. All rights reserved.
//

#import "VehicleAdditionController.h"
#import "TempletThirteenTableViewCell.h"
#import "VehicleAdditionCell.h"
#import <BRPickerView/BRPickerView.h>
#import "InputTempletTwelveTableViewCell.h"
#import "FSActionSheet.h"
#import "CedarPersonPicker.h"

@interface VehicleAdditionController ()<UITableViewDataSource,UITableViewDelegate,FSActionSheetDelegate>
@property (nonatomic,strong) UITableView *tableView;
@property (nonatomic,strong) CedarButton *comfirmBtn;
@property (nonatomic,strong) CedarButton *contactBtn;
@property (nonatomic,strong) CedarPersonPicker *picker;

@property (nonatomic,strong) UILabel *titleLblFirst;
@property (nonatomic,strong) UILabel *titleLblSecond;
@property (nonatomic,strong) UILabel *titleLblThird;
@property (nonatomic,strong) UILabel *titleLblFour;
@property (nonatomic,strong) UILabel *rentLblFour;

@property (nonatomic,strong) UIImageView *arrowImgView;

@end

@implementation VehicleAdditionController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"添加车辆";
    [self.view addSubview:self.tableView];
    [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.right.bottom.mas_equalTo(self.view);
    }];
    
//    [self.tableView addSubview:self.comfirmBtn];
//    [self.comfirmBtn mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.bottom.mas_equalTo(self.view.mas_bottom).mas_offset(-60);
//        make.left.mas_equalTo(self.view).mas_offset(kMarginOffsetX);
//        make.right.mas_equalTo(self.view).mas_offset(-kMarginOffsetX);
//        make.height.mas_offset(40);
//    }];
}



#pragma mark - Table view data source

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    if (section == 0 || section == 2 || section == 4) {
        return 40.00f;
    }else {
        return 20.00f;
    }
}

//section头部视图
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
  
    if (section == 0) {
        UIView *view = [[UIView alloc]init];
        view.backgroundColor = kAppBackgoundColor;
        [view addSubview:self.titleLblFirst];
        [self.titleLblFirst mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(view.mas_left).offset(15);
            make.centerY.equalTo(view.mas_centerY);
        }];
        return view;
    }else if (section == 2){
        UIView *view = [[UIView alloc]init];
        view.backgroundColor = kAppBackgoundColor;
        [view addSubview:self.titleLblSecond];
        [self.titleLblSecond mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(view.mas_left).offset(15);
            make.centerY.equalTo(view.mas_centerY);
        }];
        return view;
    }
    UIView *view = [[UIView alloc]init];
    view.backgroundColor = kAppBackgoundColor;
    return view;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    TempletThirteenTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"TempletThirteenTableViewCellIdentifier"];
    if (indexPath.section == 0) {
         if (indexPath.row == 0) {
             cell.btnPlaceHolder = @"请选择品牌车系 ";
             [cell updateTitle:@"车牌号"];
           }else if (indexPath.row == 1) {
               cell.btnPlaceHolder = @"请选择车型名称";
               [cell updateTitle:@"车型名称"];
           }else if (indexPath.row == 2) {
               cell.btnPlaceHolder = @"请选择座位数";
               [cell updateTitle:@"座位数"];

               
           }else if (indexPath.row == 3) {
               cell.btnPlaceHolder = @"请选择颜色";
               [cell updateTitle:@"颜色"];
               @weakify(self)
               cell.chooseBtn.clickEvent = ^{
                   @strongify(self)
               };

               
           }else if (indexPath.row == 4) {
               cell.btnPlaceHolder = @"请选择车的级别";
               [cell updateTitle:@"级别"];
               cell.chooseBtn.clickEvent = ^{
                   
               };
           }

    }else  if (indexPath.section == 1){
        InputTempletTwelveTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"InputTempletTwelveTableViewCellIdentifier"];
        if (indexPath.row == 0) {
             cell.placeholder = @"请输入车牌号";
             cell.cellTitle = @"车牌号";
             return cell;
            
        }else if (indexPath.row == 1) {
           cell.placeholder = @"请选择上牌时间";
            cell.cellTitle = @"上牌时间";
            return cell;
        }
    }else  if (indexPath.section == 2){
       InputTempletTwelveTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"InputTempletTwelveTableViewCellIdentifier"];
        if (indexPath.row == 0) {
             cell.placeholder = @"请输入司机名字";
             cell.cellTitle = @"司机名字";
            [cell setRightView:self.contactBtn size:CGSizeMake(50, 20) isShowArrow:YES];

             return cell;
            
        }else if (indexPath.row == 1) {
           cell.placeholder = @"请输入联系方式";
            cell.cellTitle = @"联系方式";
            return cell;
        }
    }else  if (indexPath.section == 3) {
       if (indexPath.row == 0) {
          cell.btnPlaceHolder = @"根据支出的自动更新";
          [cell updateTitle:@"保养时间"];
        }else if (indexPath.row == 1) {
            cell.btnPlaceHolder = @"根据支出的自动更新";
            [cell updateTitle:@"保险时间"];
        }else if (indexPath.row == 2) {
            cell.btnPlaceHolder = @"下次年审时间";
            [cell updateTitle:@"年审时间"];
        }else if (indexPath.row == 3) {
            InputTempletTwelveTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"InputTempletTwelveTableViewCellIdentifier"];
            cell.placeholder = @"请输入公里数";
            cell.cellTitle = @"公里数";
            return cell;
        }
    }else  if (indexPath.section == 4) {
        if (indexPath.row == 1) {
           VehicleAdditionCell *vehicleCell = [tableView dequeueReusableCellWithIdentifier:@"VehicleAdditionCellIdentifier"];
            return vehicleCell;
        }else {
            UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"UITableViewCelldentifier"];
            [self setupRentView:cell.contentView];

            return cell;
        }
    }
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}


 - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
     return 64;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return   5;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    if (section == 0) {
        return 5;
    }else if (section == 1 || section == 2 || section == 4) {
        return 2;
    }else if (section == 3){
        return 4;
    }
    return 0;
}

- (void)setupRentView:(UIView *)contentView {
    [contentView addSubview:self.titleLblFour];
    [contentView addSubview:self.rentLblFour];
    [contentView addSubview:self.arrowImgView];
    
    [self.titleLblFour mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(contentView).mas_offset(kMarginOffsetX);
        make.centerY.mas_equalTo(contentView.mas_centerY);
    }];
    
    [self.arrowImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(contentView).mas_offset(-kMarginOffsetX);
        make.centerY.mas_equalTo(contentView);
        make.width.mas_equalTo(8);
        make.height.mas_equalTo(14);

    }];
    
    [self.rentLblFour mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(self.arrowImgView.mas_left).mas_offset(-8);
        make.centerY.mas_equalTo(contentView.mas_centerY);
    }];
}

- (void)addsubviewIndDiverCell:(UITableViewCell *)cell {
//    [cell.contentView addSubview:self.arrowImgView];
//    [cell.contentView addSubview:self.contactBtn];
//
//    [self.arrowImgView mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.right.mas_equalTo(cell.contentView).mas_offset(-kMarginOffsetX);
//        make.centerY.mas_equalTo(cell.contentView);
//        make.width.mas_equalTo(8);
//        make.height.mas_equalTo(14);
//    }];
//
//    [self.contactBtn mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.right.mas_equalTo(self.arrowImgView.mas_left).mas_offset(-8);
//        make.centerY.mas_equalTo(cell.contentView.mas_centerY);
//    }];
    
    

}

-(void)contactsAction {
    _picker = [[CedarPersonPicker alloc] init];
    [_picker showPersionPickerWithController:self didSelectPhone:^(NSString *phoneNumber) {
        
    }];
}


- (CedarButton *)comfirmBtn{
    if (!_comfirmBtn){
        _comfirmBtn =  [CedarButton buttonWithTextForGradientForCommomn:@"确认" radius:YES];
        @weakify(self)
        _comfirmBtn.clickEvent = ^{
            @strongify(self)
        };
    }
    return _comfirmBtn;
}

- (CedarButton *)contactBtn{
    if (!_contactBtn){
        _contactBtn =  [CedarButton buttonWithTextNoStytle:@"通讯录"];
        [_contactBtn.titleLabel setFont:[UIFont systemFontOfSize:14]];
        @weakify(self)
        _contactBtn.clickEvent = ^{
            @strongify(self)
            [self contactsAction];
        };
//        [_contactBtn setImage:[UIImage imageNamed:@"commen_arrow"] forState:UIControlStateNormal];
//        [_contactBtn setTitle:@"通讯录" forState:UIControlStateNormal];

    }
    return _contactBtn;
}

- (UITableView *)tableView{
    if (!_tableView) {
        _tableView = [UIConfigure tableViewFromFactory];
        _tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.rowHeight = 64;
        _tableView.tableHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 0)];
        [_tableView registerClass:[TempletThirteenTableViewCell class] forCellReuseIdentifier:@"TempletThirteenTableViewCellIdentifier"];
        [_tableView registerClass:[InputTempletTwelveTableViewCell class] forCellReuseIdentifier:@"InputTempletTwelveTableViewCellIdentifier"];

        [_tableView registerClass:[VehicleAdditionCell class] forCellReuseIdentifier:@"VehicleAdditionCellIdentifier"];
        [_tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"UITableViewCelldentifier"];


    }
    return _tableView;
}

MACRO_UILabelWithPFCGFont(titleLblFour,@"默认租赁方式",kBlackColor,15)
MACRO_UILabelWithPFCGFont(rentLblFour,@"短期 ",kBlackColor,15)

MACRO_UILabelWithPFCGFont(titleLblFirst,@"基本信息",kGrayColor,15)
MACRO_UILabelWithPFCGFont(titleLblSecond,@"司机信息 ",kGrayColor,15)
MACRO_UILabelWithPFCGFont(titleLblThird,@"更多 ",kGrayColor,15)
MACRO_UIImageView(arrowImgView, @"commen_arrow")

@end
